<template>
  <view class="good-list" @click="goPage">
    <view class="item-img">
      <zero-lazy-load
        class="icon-img"
        :image="info.cover"
        loadingImg="https://images.tongzhuangkc.com/tz/default-good.png"
        errorImg="https://images.tongzhuangkc.com/tz/default-good.png"
        borderRadius="16"
        :height="340"
      ></zero-lazy-load>
    </view>
    <view class="item-box">
      <view class="good-name"> <text class="good-tag" v-if="info.is_top === 1">置顶</text>{{ info.content }} </view>
      <view class="good-type">
        <text class="good-price tag-text">{{ info.price }}</text>
        <text>{{ info.qinghuo_type }}</text>
      </view>
      <view class="good-info">
        <text class="tag-text">{{ info.publish_time }}</text>
        <text>浏览量{{ info.view_num }}</text>
      </view>
      <view class="good-user">
        <view class="user-info">
          <view class="user-box" :class="info.vip_type === 1 ? 'vip' : info.vip_type === 2 ? 'active' : ''">
            <image
              class="user-img"
              :src="info.member_head || 'https://images.tongzhuangkc.com/tz/default-user.png'"
              alt=""
            />
          </view>
          <text class="user-name">{{ info.member_name }}</text>
        </view>
        <text class="user-address">{{ info.city }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import { reactive, toRefs } from 'vue'
export default {
  name: 'good',
  props: {
    info: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  setup(props) {
    const state = reactive({
      info: props.info,
    })
    const goPage = () => {
      uni.navigateTo({
        url: `/subpackage-goods/detail/index?id=${state.info.goods_id}`,
      })
    }
    return {
      ...toRefs(state),
      goPage,
    }
  },
}
</script>

<style lang="scss" scoped>
.good-list {
  overflow: hidden;
  img {
    object-fit: cover;
  }
  .item-img {
    height: 342rpx;
  }
}
.icon-img {
  width: 100%;
  height: 342rpx;
  object-fit: cover;
  overflow: hidden;
  border-radius: 16rpx;
  image {
    height: 342rpx !important;
    object-fit: cover;
  }
}
.item-box {
  padding-top: 16rpx;
  background: #fff;
  .good-name {
    max-width: 100%;
    min-height: 76rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    font-weight: bold;
    @include text-ellipsis(2);
    .good-tag {
      padding: 0 5rpx;
      height: 40rpx;
      background: #e94148;
      margin-right: 24rpx;
      font-size: 24rpx;
      color: #fff;
      text-align: center;
      line-height: 40rpx;
      border-radius: 6rpx 6rpx 6rpx 6rpx;
    }
  }
  .good-type {
    margin: 8rpx 0;
  }
  .good-type,
  .good-info {
    font-size: 24rpx;
    color: #7f8798;
    .tag-text {
      margin-right: 8rpx;
    }
    .good-price {
      color: #f40;
      font-size: 32rpx;
    }
  }
  .good-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 10rpx;
    .user-info {
      display: flex;
      align-items: center;
      width: 60%;
      .user-box {
        margin-right: 8rpx;
        width: 48rpx;
        height: 48rpx;
        position: relative;
        .user-img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
        &::before {
          content: '';
          display: block;
          width: 24rpx;
          height: 24rpx;
          position: absolute;
          bottom: 0;
          right: 0;
        }
        &.active {
          &::before {
            background: url('https://images.tongzhuangkc.com/tz/vip2.png') no-repeat;
            background-size: 100% 100%;
          }
        }
        &.vip {
          &::before {
            background: url('https://images.tongzhuangkc.com/tz/vip.png') no-repeat;
            background-size: 100% 100%;
          }
        }
      }
      .user-name {
        color: #2b303b;
        font-size: 24rpx;
        width: calc(100% - 48rpx);
        @include text-ellipsis(1);
      }
    }
    .user-address {
      font-size: 24rpx;
      color: #7f8798;
    }
  }
}
</style>
